import {
  ADD_GOODS_TO_CART,
  INCREMENT_CART_GOODS_COUNT,
  CHECKED_GOODS_SELECTION,
  DEC_GOODS_COUNT,
  INC_GOODS_COUNT,
  CHECKED_ALL_GOODS_SELECTION,
} from './mutations_types'

export default {
  [ADD_GOODS_TO_CART](state, payload) {
    state.cartList.push(payload)
  },
  [INCREMENT_CART_GOODS_COUNT](state, payload) {
    state.cartList[payload].count++
  },
  [CHECKED_GOODS_SELECTION](state, payload) {
    let goods = state.cartList[payload]
    goods.checked = !goods.checked
  },
  [DEC_GOODS_COUNT](state, payload) {
    state.cartList[payload].count--
  },
  [INC_GOODS_COUNT](state, payload) {
    state.cartList[payload].count++
  },
  [CHECKED_ALL_GOODS_SELECTION](state, payload) {
    state.cartList.forEach(item => item.checked = payload)
  },
}